Grokking Microservices Design Patterns
Rate this course
Ask Author
Contribute
Back to course home

0% completed

Vote For New Content
Introduction
Who Should Take This Course?
The Course at a Glance
Strangler Fig Pattern
Introduction
The Problem: Legacy Systems
The Strangler Pattern: A Solution
The Architecture of the Strangler Pattern
Strangler Pattern: A Detailed Example
Key Insights and Implications
API Gateway Pattern
Introduction to the API Gateway Pattern
Advantages of API Gateway Pattern
API Gateway Pattern: An Example
Performance Implications
System Design Example
Backends for Frontends (BFF) Pattern
Introduction to BFF
The Problem: Traditional Backend Models
The Architecture of the BFF Pattern
BFF Pattern: An Example
Performance Implications
System Design Examples
Service Discovery Pattern
What is Service Discovery Pattern?
The Problem: Service Coordination in Distributed Systems
Service Discovery Pattern: A Solution
The Architecture of the Service Discovery Pattern
The Inner Workings of the Service Discovery Pattern
Service Discovery Pattern: An Example
Performance Implications and Special Considerations
System Design Examples
Security Considerations
Circuit Breaker Pattern
Introduction
The Problem: The Struggles of Distributed Systems and Service Failures
The Circuit Breaker Pattern: An Effective Shield Against Cascading Failures
Circuit Breaker Pattern: An Example
Performance Implications and Special Considerations
System Design Examples
Summary
Bulkhead Pattern
Introduction
The Problem: Failure Propagation in Distributed Systems
The Bulkhead Pattern: A Solution
The Architecture
The Inner Workings
Bulkhead Pattern: A Example
Performance Implications and Special Considerations
System Design Examples
Conclusion
Retry Pattern
Introduction
The Retry Pattern: A Solution to Unreliable External Resources
The Architecture of the Retry Pattern
Retry Pattern: An Example
Performance Implications
Use Cases and System Design Examples
Conclusion
Sidecar Pattern
Introduction to the Sidecar Pattern
The Problem: Monolithic Application Management
A Solution to the Monolithic Mayhem
The Architecture of the Sidecar Pattern
Sidecar Pattern: Bringing Theory to Practice with an Example
Performance Implications
System Design Examples: Bringing the Sidecar Pattern to Life
Saga Pattern
Introduction to Saga Pattern
The Problem: Traditional Transaction Models
The Saga Pattern: A Solution
The Architecture of the Saga Pattern
The Inner Workings of the Saga Pattern
Saga Pattern: A Example
Performance Implications
System Design Examples
Conclusion
Event-Driven Architecture Pattern
Introduction
The Problem: Managing Complex Interactions in Distributed Systems
Event-Driven Architecture: A Promising Solution
The Architecture of the Event-Driven Architecture Pattern
The Inner Workings of the Event-Driven Architecture Pattern
Event-Driven Architecture Pattern: An Example
Performance Implications and Special Considerations
Use Cases and System Design Examples
Conclusion
CQRS (Command Query Responsibility Segregation)
Introduction
The Problem: Traditional CRUD Operations
CQRS Pattern: A Solution
The Architecture of the CQRS Pattern
The Inner Workings of the CQRS Pattern
CQRS Pattern: An Example
Issues, Special Considerations, and Performance Implications
System Design Examples
Introduction
The Problem: Configuration Management in a Microservices Architecture
The Solution: Configuration Externalization Pattern
Unveiling the Architecture: How Does Configuration Externalization Work?
Delving into Code: An Example
Considerations and Implications
Use Cases and Real-world Examples
Conclusion
Embrace the Future of Software Architecture
The Inner Workings of the CQRS Pattern

A Journey of a Command

A command signifies an intention to change the state of our system. Let's follow the journey of a command to understand how CQRS processes it.

Imagine a user wants to update their address in an e-commerce application. The command would be something like 'Update User Address'. This command would trigger a chain of events within the system.

Validation

Before anything else, the command is validated. This validation can involve checks for data format, permissions, and other business rules. In our example, is the new address in a valid format? Does the user have the necessary permissions to change their address? If the command passes these validations, it moves on to the next stage; otherwise, it's rejected.

Handling the Command

Once validated, the command is handled by the command handler. This component is the workhorse of the command side of CQRS. It's responsible for updating the state of the system based on the command. For instance, it updates the user's address in the system.

Generating Events

Every command leads to a change in state, represented by an event. In our case, the event could be 'User Address Updated'. This event is stored in the event store, serving as a historical record of all changes in the system.

The Query's Quest

A query, in essence, is a request for data. Let's say our user now wants to view their updated address. They issue a query: 'Get User Address'. How does CQRS handle it?

Unlike commands, queries don't require validation or event generation. They're simply processed by the query handler, which fetches the required data. In this case, it fetches the user's address from the system and displays it to the user.

Synchronizing Commands and Queries

We've explored the separate journeys of commands and queries. But how do these two sides stay synchronized? This is where Event Sourcing comes into play.

Remember the 'User Address Updated' event generated when the user updated their address? This event is replayed on the query side to update its state. In other words, the user's updated address is reflected in the query model. Thus, Event Sourcing ensures that despite working separately, the command and query sides are always in sync.

The Architecture of the CQRS Pattern
CQRS Pattern: An Example
Mark as Completed

On this page

A Journey of a Command

Validation

Handling the Command

Generating Events

The Query's Quest

Synchronizing Commands and Queries